/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.poll.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.poll.monitor.entity.PollMonitorFactorEntity;
import com.hopes.bizz.poll.monitor.mapper.PollMonitorFactorMapper;
import com.hopes.bizz.poll.monitor.service.PollMonitorFactorService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 监控点监控因子
 *
 * @author yumr
 * @date 2023-05-22 14:47:33
 */
@Service
public class PollMonitorFactorServiceImpl extends ServiceImpl<PollMonitorFactorMapper, PollMonitorFactorEntity> implements PollMonitorFactorService {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeByPollMonitorFactor(PollMonitorFactorEntity pollMonitorFactor) {
        final List<PollMonitorFactorEntity> monitorFactorEntityList = baseMapper.selectList(Wrappers.query(pollMonitorFactor));
        baseMapper.deleteBatchIds(monitorFactorEntityList.stream().map(PollMonitorFactorEntity::getId).filter(Objects::nonNull).collect(Collectors.toList()));
        return true;
    }

    @Override
    public PollMonitorFactorEntity getMonitorFactorBySiteAndFactorId(Long monitorSiteId, Long factorInfoId) {
        final LambdaQueryWrapper<PollMonitorFactorEntity> wrapper = Wrappers.<PollMonitorFactorEntity>lambdaQuery().eq(PollMonitorFactorEntity::getMonitorSiteId, monitorSiteId)
                .eq(PollMonitorFactorEntity::getFactorId, factorInfoId);
        return baseMapper.selectOne(wrapper);
    }
}
